---
title: |
  | Replication Material 
  | 
  | Support for radical parties in Western Europe: the role of long- and short-term dynamics
  |
  | Electoral Studies 2020
  |
author: "Hanspeter Kriesi and Julia Schulte-Cloos"
date: "April 2020"
output: 
  bookdown::html_document2: 
    theme: cosmo
    highlight: textmate
    toc: true
    toc_float:
      collapsed: false
      smooth_scroll: false
    code_folding: hide  
---

```{r setup, include=FALSE}

knitr::opts_chunk$set(echo = TRUE)

# first install package management tool pacman
install.packages("pacman")

pacman::p_load(
  haven,
  broom,
  ggplot2,
  knitr,
  devtools,
  lubridate,
  extrafont,
  kableExtra,
  readxl,
  gridExtra,
  stringr,
  Statamarkdown,
  grid,
  tiff,
  tidyverse
)


```

# Load Replication Data

We first read in two datasets: 

1. The raw ESS cumulative file (selected countries, selected variables to reduce the file size, `ess_radical_hpkjsc.csv`). We have also added the Parlgov `party_id` of the party that a respondent has voted for (see the [Parlgov Databse](https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/F0YGNC)) and the [Oesch class scheme](http://philippejoly.net/files/code/oesch-class-ess-R/vignette.html) to this dataset.

2. The pre-processed dataset `esstime_cabinetparty.csv` which contains information on whether the respective party that a respondent voted for had been part of the cabinet **at the time when the ESS interview was conducted.** The `cabinet_status` variable corresponds to the information provided in the Parlgov database. The datset contains also additional information on the Parlgov party family classification (`family_id`) and the corresponding variable that we will use in our analysis (`family_parlgov`) variable. 

```{r read-raw-data, message=FALSE}

essintegrated <- read_csv2(
  file = "./data/ess_radical_hpkjsc.csv",
  guess_max = c(20000)
)

# spec(essintegrated)

esstime_cabinetparty <- read_csv2(file = "./data/esstime_cabinetparty.csv")

# spec(esstime_cabinetparty)
```



## Indicator variable for radical left or radical right party

We add an indicator variable to the the `esstime_cabinetparty` data that takes the value 1 if a respondent has voted for a radical right party (`rrp`) or radical left party (`rlp`) and takes the value 0 if a respondent has voted for a non-radical mainstream party, which HP Kriesi classified based on the parlgov family classification, i.e. parties that are agrarian, Christian democratic, conservative, liberal or social democratic according to this classification. 
We consider all parties that are classified as radical left and radical right parties according to the ParlGov database [@Doering.2018]. In a few cases, we have adjusted Parlgov’s classification of parties: we attribute the Swiss SVP and the Finnish Finn party to the radical right family. We further include the Danish Socialist People Party as a radical left party (see e.g. @Bakker.2015) and exclude M5S from the analyses as the party's profile was highly ambiguous regarding any left-right position during its early phases. Finally, we classify the Italian Northern League party as a separatist party during the ESS round 1. 

The indicator variable is missing for all respondents who did not vote (`vote != 1`).

```{r indicator-rlp-rrp-variable}

# Indicator variables for radical right party (rrp) or radical left party (rlp) support
esstime_cabinetparty <- esstime_cabinetparty %>%
  mutate(
    rrp = case_when( # radical right parties
      family_parlgov == 7 & vote == 1 ~ 1,
      # non-radical / mainstream parties with parlgov families:
      # 1 agrarian, 2 christian, 4 conservative, 6 liberal, 8 social democracy
      family_parlgov %in% c(1, 2, 4, 6, 8) & vote == 1 ~ 0,
      TRUE ~ NA_real_
    ),
    rlp = case_when( # radical left parties
      family_parlgov == 3 & vote == 1 ~ 1,
      # non-radical / mainstream parties with parlgov families:
      # 1 agrarian, 2 christian, 4 conservative, 6 liberal, 8 social democracy
      family_parlgov %in% c(1, 2, 4, 6, 8) & vote == 1 ~ 0,
      TRUE ~ NA_real_
    )
  )
```




## Party offer typology: only radical right (1), only radical left (2), both (3)

We generate a variable called `party_offer` that indicates which types of relevant parties existed at the time of the ESS interview. We consider a party actor as relevant for a country's party system if at least 30 respondents report to have voted for this party (or feel close to this party if no information on the vote choice is available.) 

The variable takes the following values: 

- only radical right: `party_offer == 1`
- only radical left: `party_offer == 2`
- radical left *and* radical right: `party_offer == 3`


```{r party-offer, eval=T}

partyoffer <- esstime_cabinetparty %>%
  group_by(country_name, essround, party_name_english) %>%
  filter(rrp == 1 | rlp == 1) %>%
  summarise(
    countrrp = sum(rrp, na.rm = T),
    countrlp = sum(rlp, na.rm = T)
  ) %>%
  ungroup() %>%
  # consider only parties that have at least 30 respondents who reported to have voted for them
  mutate(
    rrp = if_else(countrrp < 30, 0, 1),
    rlp = if_else(countrlp < 30, 0, 1)
  ) %>%
  ungroup() %>%
  group_by(country_name, essround) %>%
  summarise(
    rrp = max(rrp, na.rm = T),
    rlp = max(rlp, na.rm = T)
  ) %>%
  mutate(party_offer = case_when(
    rrp == 0 & rlp == 0 ~ 0,
    rrp == 1 & rlp == 0 ~ 1,
    rrp == 0 & rlp == 1 ~ 2,
    rrp == 1 & rlp == 1 ~ 3
  ))


# join to the esstime_cabinetparty
esstime_cabinetparty <- left_join(esstime_cabinetparty,
  partyoffer %>%
    select(country_name, essround, party_offer),
  by = c("country_name", "essround")
)

```

The resulting classification places each country for which we have data from the respective rounds of the ESS cumulative file in one of the three categories. Figure \@ref(fig:party-offer-plot-grid) offers an overview over the resulting classification across ESS country years. 

## Figure A1: Party offer across countries

```{r party-offer-plot, fig.height=6, fig.width=9, fig.cap="Party offer across countries and ESS years", warning=FALSE}


plot_partyoffer <- ggplot(
  data = esstime_cabinetparty %>%
    mutate(offer = case_when(
      `party_offer` == 1 ~ "Radical Right",
      `party_offer` == 2 ~ "Radical Left",
      `party_offer` == 3 ~ "Both"
    )) %>%
    filter(!is.na(offer)) %>% 
    # generate ess_year variable 
    mutate(ess_year = case_when(
      essround == 1 ~ 2002, 
      essround == 2 ~ 2004, 
      essround == 3 ~ 2006, 
      essround == 4 ~ 2008, 
      essround == 5 ~ 2010, 
      essround == 6 ~ 2012, 
      essround == 7 ~ 2014, 
      essround == 8 ~ 2016
      )),
  aes(
    x = ess_year,
    y = forcats::fct_rev(cntry),
    fill = offer
  )
) +
  labs(
    x = "ESS Year",
    y = "Country"
  ) +
  scale_fill_brewer(palette = "Paired") +
  scale_x_continuous(name = "ESS Year", 
                     breaks = c(2002, 2004, 2006, 2008, 2010, 2012, 2014, 2016)) +
  geom_tile(color = "white") +
  theme(
    legend.position = "bottom",
    legend.title = element_blank(),
    panel.background = element_blank(),
    panel.grid.major = element_blank()
  ) +
  theme(text = element_text(
    size = 50
  ))

ggsave(
  filename = "plot_partyoffer.tif",
  device = "tiff",
  height = 4, width = 9,
  unit = "in"
)
```



```{r party-offer-plot-grid, fig.height=4, fig.width=7, fig.cap="Party offer across countries and ESS years", echo=FALSE}

grid.raster(readTIFF("plot_partyoffer.tif"))

```



## Government participation of radical parties and support of minority governments

Next, we are interested in constructing an extendend version of the Parlgov `cabinet_status` variable that includes all those cases in which radical left and radical right parties had not been part of the government, but supported minority governments. 

In the ESS rounds included in the ESS cumulative dataset, among radical right parties, this is the case in Denmark (from end of 2001 to end of 2011) and for the Netherlands (end of 2010 to early 2012). Radical left parties have been supporting minority governments in Denmark (from early 2014 to mid 2015), in Portugal (from end of 2015 to end of 2019) and in Sweden (2002 - 2006, i.e. during ESS round 1, 2 and early parts of the fieldwork of round 3, and from 2014-2018, i.e. during ESS round 7 and 8). 

The resulting `cabinet2` is a variable that takes the value 1 if the radical left or radical right party that a respondent voted for was supporting a minority government at the time of the ESS interview.  

The two variables `rrp_cabinet` and `rlp_cabinet` integrate the indirect government support and the direct government participation. The variables take the value 1 if the respondent voted for a radical right or radical left party that has either been part of the government (`cabinet_status==1`) or has been supporting a government (`cabinet2==1`).



```{r cabinet-status-minority-governments, warning=FALSE, message=FALSE}

# cabinet2: indicator variable that measures whether respondent voted for a radical left/right party that supported a minority government at the time of the interview
esstime_cabinetparty = esstime_cabinetparty %>% 
  mutate(cabinet2 = case_when(
    # Denmark: Danish People's party supported Conservative government after 2001
    rrp==1 & country_name=="Denmark" & party_id == 1418 &
      sdate >= lubridate::ymd("2001-11-27") & edate <= lubridate::ymd("2011-10-01") ~ 1, 
    # Netherlands: Party for Freedom (PVV) supports minority right government between VVD and CDA
    rrp==1 & country_name=="Netherlands" & party_id==1501 & 
      sdate >= lubridate::ymd("2010-10-14") & edate <= lubridate::ymd("2012-04-22") ~ 1, 
    # Denmark Socialist People's party: support of the Thorning-Schmidt II Cabinet after they left the government
    rlp==1 & country_name=="Denmark" & party_id ==1644 & 
      sdate >= lubridate::ymd("2014-02-03") & edate <= lubridate::ymd("2015-06-27") ~ 1, 
    # Portuguese Communist party supports the government headed by António Costa, together with the Left Bloc and the Greens
    rlp==1 & country_name=="Portugal" & (party_id==514 | party_id==557) & 
      sdate >= lubridate::ymd("2015-11-26") & edate <= lubridate::ymd("2019-10-25") ~ 1, 
    # Sweden: support of the third Persson cabinet by the Left Party (party_id = 882) together with the Greens from 2002-2006
    rlp==1 & country_name=="Sweden" & party_id==882 & 
      sdate >= lubridate::ymd("2002-10-21") & edate <= lubridate::ymd("2006-10-04") ~ 1, 
    # Sweden: support of the first Lövfen cabinet (Social democrats and Greens) by the Left Party (party_id = 883) from 2014- 2018
    rlp==1 & country_name=="Sweden" & party_id==882 & 
      sdate >= lubridate::ymd("2014-10-02") & edate <= lubridate::ymd("2018-09-08") ~ 1
    )
  )

# integrated cabinet variable: if "cabinet_status" (parlgov) == 1 or if cabinet2 == 1 (minority governments)
esstime_cabinetparty <- esstime_cabinetparty %>%
  mutate(cabinet = case_when(
    cabinet_status == 1 ~ 1,
    cabinet2 == 1 ~ 1,
    cabinet_status == 0 ~ 0
  ))

# integrated rrp_cabinet and rlp_cabinet variable
esstime_cabinetparty <- esstime_cabinetparty %>%
  mutate(
    rrp_cabinet = case_when(
      rrp == 1 & cabinet == 1 ~ 1,
      rrp == 1 & cabinet == 0 ~ 0,
      TRUE ~ NA_real_
    ),
    rlp_cabinet = case_when(
      rlp == 1 & cabinet == 1 ~ 1,
      rlp == 1 & cabinet == 0 ~ 0,
      TRUE ~ NA_real_
    )
  )
```


Finally, we construct two related indicator variables that operate on the level of the time period that each cabinet spans: `rrp_cabinet_all` and `rlp_cabinet_all` identify all those respondents that were interviewed while a radical right or radical left party was in government or supporting a minority government in a given country (`rrp_cabinet_all == 1` and `rlp_cabinet_all==1`, respectively) or while this was not the case (`rrp_cabinet_all == 0` and `rlp_cabinet_all==0`, respectively).


```{r radical-government-indicator, warning=FALSE}

# rrp_cabinet_all and rlp_cabinet_all:
# identifier that identifies all respondents during a cabinet with a rrp or rlp party in government
esstime_cabinetparty <- esstime_cabinetparty %>%
  group_by(cabinet_id) %>%
  mutate(
    rrp_cabinet_all = max(rrp_cabinet, na.rm = T),
    rlp_cabinet_all = max(rlp_cabinet, na.rm = T)
  ) %>%
  mutate(
    rrp_cabinet_all = if_else(is.infinite(rrp_cabinet_all), NA_real_, rrp_cabinet_all),
    rlp_cabinet_all = if_else(is.infinite(rlp_cabinet_all), NA_real_, rlp_cabinet_all)
  )
```



```{r radgov-essrounds}

options(knitr.kable.NA = "")
kable(esstime_cabinetparty %>%
  group_by(cntry, essround) %>%
  summarise(rrp_cabinet_all = sum(rrp_cabinet_all, na.rm = T)) %>%
  filter(!is.na(rrp_cabinet_all) & rrp_cabinet_all != 0) %>%
  arrange(essround, cntry) %>%
  pivot_wider(
    id_cols = cntry,
    names_from = essround,
    values_from = rrp_cabinet_all,
    names_prefix = "ESS "
  ) %>%
  arrange(cntry),
caption = "Respondents in ESS Rounds during a Radical Right Government",
) %>%
  kableExtra::kable_styling(bootstrap_options = "striped")




options(knitr.kable.NA = "")
kable(esstime_cabinetparty %>%
  group_by(cntry, essround) %>%
  summarise(rlp_cabinet_all = sum(rlp_cabinet_all, na.rm = T)) %>%
  filter(!is.na(rlp_cabinet_all) & rlp_cabinet_all != 0) %>%
  arrange(essround, cntry) %>%
  pivot_wider(
    id_cols = cntry,
    names_from = essround,
    values_from = rlp_cabinet_all,
    names_prefix = "ESS "
  ) %>%
  arrange(cntry),
caption = "Respondents in ESS Rounds during a Radical Left Government",
) %>%
  kableExtra::kable_styling(bootstrap_options = "striped")
```




## Figure A2: Radical parties in government and opposition across countries

Figure \@ref(fig:government-plot-grid) shows the government participation or minority government support by radical parties across countries. The shading indicates how many respondents were interviewed during the respective government period, ranging from around 100 to 2500.


```{r government-plot, message=FALSE, warning=FALSE}

govplot <- esstime_cabinetparty %>%
  group_by(
    cntry, cabinet_id,
    sdate, edate
  ) %>%
  filter(family_parlgov %in% c(1, 2, 3, 4, 6, 7, 8)) %>%
  filter(vote == 1) %>%
  summarise(
    count_rlp_cabinet = n(),
    count_rrp_cabinet = n(),
    rrp_cabinet = max(rrp_cabinet, na.rm = T),
    rlp_cabinet = max(rlp_cabinet, na.rm = T)
  ) %>%
  filter(rrp_cabinet == 1 | rlp_cabinet == 1) %>%
  mutate(government = case_when(
    rrp_cabinet == 1 ~ "Radical Right in Government",
    rlp_cabinet == 1 ~ "Radical Left in Government",
    TRUE ~ NA_character_
  )) %>%
  select(
    cntry, sdate, edate, government,
    count_rlp_cabinet,
    count_rrp_cabinet
  ) %>%
  mutate(countresp = case_when(
    government == "Radical Right in Government" ~ count_rrp_cabinet,
    government == "Radical Left in Government" ~ count_rlp_cabinet
  ))

cols <- c("Radical Right in Government" = "#b2df8a", "Radical Left in Government" = "#1f78b4")

plot_government <- ggplot(
  data = govplot,
  aes(
    xmin = sdate,
    xmax = edate,
    y = forcats::fct_rev(cntry),
    alpha = countresp,
    color = government
  ),
  size = 8
) +
  labs(y = "Country") +
  geom_linerange(size = 8) +
  scale_x_date(date_breaks = "1 year", date_labels = "%Y") +
  scale_color_manual(values = cols, "") +
  scale_alpha_continuous(guide = FALSE) +
  guides(fill = guide_legend(ncol = 2, byrow = TRUE)) +
  theme(
    legend.position = "bottom",
    legend.box = "vertical",
    panel.background = element_blank(),
    panel.grid.major = element_blank(),
    axis.text.x = element_text(angle = 45)
  ) +
  theme(text = element_text(
    size = 50
  ))


ggsave(
  filename = "plot_government.tif",
  device = "tiff",
  height = 6, width = 9,
  unit = "in"
)
```


```{r government-plot-grid, fig.height=4, fig.width=9, fig.cap="Cabinet status and minority government support by radical parties", echo=FALSE}

grid.raster(readTIFF("plot_government.tif"))
```


## Integration of all variables - join `esstime_cabinetparty` and `essintegrated`

We integrate all relevant respondent level variables (stored in `essintegrated`) with the information on the cabinet status of a the party that a respondent has voted for (stored in `esstime_cabinetparty`.)

```{r essintegrate-all}


essintegrated_all <- left_join(essintegrated %>%
  select(-cname, -vote),
esstime_cabinetparty %>% 
  ungroup(),
by = c("idno", "cntry", "essround",
  "countrystring" = "country_name",
  "party_id"
  )
)


write_csv(essintegrated_all %>%
  select(-sdate, -edate), path = "data/essintegrated_all.csv", na = ".")
```


# Operationalisation of control variables 

The following chunk executes the operationalization as implemented by HP Kriesi. You need to install the `Statamarkdown` package on your machine to execute this code directly from within R. If you prefer to execute the code from within Stata, please copy-paste the code to a do-file, store this do-file in the same directory in which you also store the folder "data" containing the `essintegrated_all.csv` and execute the code. 

The do-file loads the ESS cumulative dataset (raw dataset for selected countries, selected variables), which has been augmented by J Schulte-Cloos to include:  

- Oesch class scheme (as integrated by Philippe Joly, WZB).
- Parlgov party-level information based on a respondent's vote choice (or party she feels close to, but no information on the vote choice is available).
- Parlgov family classification, which has been adjusted as indicated by HP Kriesi and as reported in the main article.
- Current cabinet status (Parlgov information) or support status for minority government (added) of the party voted for at the time when the respondent was interviewed, see Figure \@ref(fig:government-plot-grid). 


```{r operationalisation-hpk, engine='stata', echo=F, message=F, warning=F, include=FALSE, eval=TRUE}

**************************************************************************************************************
* This script runs HP Kriesi's operationalisation for variables used in 
* "Support for radical parties in Western Europe: the role of long- and short-term dynamics"

* It loads the ESS cumulative dataset (raw dataset for selected countries, selected variables) 
* This dataset has been augmented by J Schulte-Cloos for 
* - Oesch class scheme (as integrated by Philippe Joly, WZB, see the reference in the online appendix)
* - Parlgov party-level information based on a respondent's vote choice 
* 	(or party she feels close to if no information on the vote choice available)
* - Parlgov family classification, which has been adjusted as indicated by HP Kriesi and as reported in the 
* 	main article 
* - Current cabinet status (Parlgov information) or support status for minority government (added) of the party voted for, 
* 	at the time when the respondent was interviewed 
**************************************************************************************************************
clear	
import delimited ".\data\essintegrated_all.csv"

set more off
eststo clear
estimates clear
set scheme s1mono


***********************
* Indepent variables
***********************


* male
gen male=gndr
recode male (2=0)
label def male 0 "female" 1 "male"
label val male male
tab1 male


* binary class indicators out of the Oesch class scheme. 
gen smallb=class8
recode smallb (2=1)(.=.)(else=0)
gen technical=class8
recode technical (3=1)(.=.)(else=0)
gen prod_worker=class8
recode prod_worker (4=1)(.=.)(else=0)
gen manager=class8
recode manager (5=1)(.=.)(else=0)
gen clerk=class8
recode clerk (6=1)(.=.)(else=0)
gen socio_cult=class8
recode socio_cult (7=1)(.=.)(else=0)
gen service_worker=class8
recode service_worker (8=1)(.=.)(else=0)
gen libprof=class8
recode libprof (1=1)(.=.)(else=0)
tab1 libprof


* Age variables
gen agea1=(agea-13)/110

label var agea1 "age"
gen agea2=agea^2
label var agea2 "age sq"

* Education
gen educ=edulvla
recode educ (55=.)
label def educ 1 "low" 2 "lower secondary" 3 "upper secondary" 4 "post-sec/non-tertiary" 5 "tertiary"
label val educ educ
tab1 educ

gen educ1=educ/5


* Economic difficulties, coping 
* impute missing value for ESS round 1 and 2 in France (22.20% (3342) observations imputed)
xi: impute hincfel hinctnta educ i.class8 agea agea2 gndr if cntry=="FR", gen(copingi)
gen hincfeli = hincfel
replace hincfeli = copingi if cntry=="FR" & (essround==1 | essround==2)
gen coping = hincfeli/4
label var coping "economic difficulties"
tab1 coping



* Trust in institutions
factor trstprl trstplt trstprt if essround != 1
predict insttrust if essround != 1
* trust in parties not in essround 1
factor trstprl trstplt if essround == 1
predict insttrust_round1 if essround == 1
replace insttrust = insttrust_round1 if essround ==1 
drop insttrust_round1
egen mininsttrust=min(insttrust)
egen maxinsttrust=max(insttrust)
gen insttrust1=(insttrust-mininsttrust)/(maxinsttrust-mininsttrust)
*distrust in institutions
replace insttrust1=-1*(insttrust1-1)
tabstat insttrust1 , stat(mean min max sd)

* Satisfaction with democracy and satisfaction with the government
gen stfdem1=stfdem/10
gen stfgov1=stfgov/10

* Dissatisfaction with democracy
replace stfdem1=-stfdem1
* Government distrust (~ dissatisfaction with the government)
replace stfgov1=-stfgov1

* General dissatisfaction with institutions
factor insttrust1 stfdem1 stfgov1 
predict generaldiss
label var generaldiss "political dissatisfaction"

capture drop miny maxy
egen miny=min(generaldiss)
egen maxy=max(generaldiss)
replace generaldiss=(generaldiss-miny)/(maxy-miny)
drop miny maxy
tabstat generaldiss , stat(min max mean n)

*7.45% (17327) observations imputed
impute generaldiss insttrust1 stfdem1 stfgov1 stfeco stflife , gen(generaldissx)
egen miny=min(generaldissx)
egen maxy=max(generaldissx)
replace generaldiss=(generaldissx-miny)/(maxy-miny)
drop miny maxy 
drop generaldissx
tabstat generaldiss , stat(min max mean n)


* Income for ESS rounds 1-3: hinctnt and for ESS rounds 4-8: hinctnt
 
* Impute income for waves 1-3 (get estimates for 24.70% (22488) missing)
xi: impute hinctnt educ hincfel i.class8 agea agea2 gndr if essround<4, gen(income_a)
* Impute income for waves 4-8 (get estimates for 19.39% (27422) missing)
xi: impute hinctnta educ hincfel i.class8 agea agea2 gndr if essround>=4, gen(income_b)

gen income = . 
replace income = income_a if essround < 4 
replace income = income_b if essround >= 4
drop income_a income_b

* Income standardised
gen income1=income/10


* L-R Scale
gen lrscale1=lrscale/10
replace lrscale1=.5 if inlist(lrscale,.b,.c,.d)
* 24,115 missing
tab1 lrscale1



* Immigration scale
impute imsmetn imdfetn impcntr imbgeco imueclt imwbcnt  , gen(im1)
impute imdfetn imsmetn impcntr imbgeco imueclt imwbcnt  , gen(im2)
impute impcntr imsmetn imdfetn imbgeco imueclt imwbcnt  , gen(im3)
impute imbgeco imsmetn imdfetn impcntr imueclt imwbcnt  , gen(im4)
impute imueclt imsmetn imdfetn imbgeco impcntr imwbcnt  , gen(im5)
impute imwbcnt imsmetn imdfetn imbgeco impcntr imueclt  , gen(im6)
factor im1-im6 , factor(1)
rotate
predict immig
drop im1 im2 im3 im4 im5 im6


egen minimmig=min(immig)
egen maximmig=max(immig)
gen immig1=(immig-minimmig)/(maximmig-minimmig)
tabstat immig1 , stat(mean sd min max)


* Gays and Lesbians live free as they wish, *recode high values as being culturally liberal
gen freehms1 = freehms 
recode freehms1 (1=5)(2=4)(3=3)(4=2)(5=1)
replace freehms1=freehms1/5


* European integration should go further
gen euftf1=euftf/10
impute euftf1 freehms1 immig1 educ1 agea agea2 gndr trstep trstun , gen(euftf1i)
* 30.73% (71454) observations imputed
tabstat euftf1i , stat(mean sd min max n)

* Government should reduce differences in income levels
gen gincdif1=gincdif
recode gincdif1 (1=1)(2=.75)(3=.5)(4=.25)(5=0)



* ESS-country years with established vs rising rrp in crisis years

* only unambiguous cases considered
* Lega (Italy) Popular Orthodox Rally vs Golden Dawn (Greece), and Swiss People's Party not included in this part of the analysis 

* rrp_new: dummy variable that indicates whether a country has a established (0) or rising (1) radical right party offer
gen rrp_new=.
* 1 Austria, 2 Belgium, 8 Denmark, 12 France, 22 Netherlands, 23 Norway
replace rrp_new=0 if inlist(country,1,2,8,12,22,23) & ess_year > 2008 & inlist(party_offer,1,3)
* 26 Sweden, 11 Finland, 7 Germany, 13 UK 
replace rrp_new=1 if inlist(country,7,11,13,26) & ess_year > 2008 & inlist(party_offer,1,3)
label define rrp_new 0 "established before 2008" 1 "rising after 2008"
label val rrp_new rrp_new
tab1 rrp_new 


* vote for established radical right 
gen vote_rrp_estab = . 
* vote for established radical right in 1 Austria, 2 Belgium, 8 Denmark, 12 France, 22 Netherlands, 23 Norway, 26 Sweden
replace vote_rrp_estab=0 if rrp==0 & inlist(country,1,2,8,12,22,23,26) & ess_year > 2008 & vote==1 & inlist(family_parlgov,1,2,4,6,8)
replace vote_rrp_estab=1 if rrp==1 & inlist(country,1,2,8,12,22,23,26) & ess_year > 2008 & vote==1 


* vote for rising radical right 
* vote choice for a radical left party in all countries that have a rising radical right party
gen vote_rrp_new = . 
replace vote_rrp_new=0 if rrp==0 & inlist(country,7,11,13,26) & ess_year > 2008 & vote==1 & inlist(family_parlgov,1,2,4,6,8)
* vote for rising radical right in 26 Sweden (Sweden Democrats), 11 Finland (True Finns), 13 UK (UKIP)
replace vote_rrp_new=1 if rrp==1 & inlist(country,11,13,26) & ess_year > 2008 & vote==1 
* rising: AfD in 7 Germany (specify party_id to exclude respondents who voted for NPD)
replace vote_rrp_new=1 if rrp==1 & vote==1 & country==7 & party_id==2253



* ESS-country years with estblished vs rising radical left in crisis years

* rlp_new: dummy variable that indicates whether a country has a established (0) or rising (1) radical left party offer
label define rlp_new 0 "other" 1 "rising after 2008"
gen rlp_new=.
* 2 Belgium, 5 Cyprus, 7 Germany, 8 Denmark, 11 Finland, 12 France, 22 Netherlands, 23 Norway, 26 Sweden
replace rlp_new=0 if inlist(country,2,5,7,8,11,12,22,23,26) & ess_year > 2008 & inlist(party_offer,2,3)
* 10 Spain, 17 Ireland, 25 Portugal, 14 Greece
replace rlp_new=1 if inlist(country,10,14,17,25) & ess_year > 2008 & inlist(party_offer,2,3)
label val rlp_new rlp_new
tab1 rlp_new 
tab2 country rlp_new 


* vote choice for rising radical left in countries with rising radical left party 
* Sinn Fein (2217) People Before Profit (1804) Syriza (1441,1592), Podemos (2376) En Marea (2604), Left Bloc, Portugal BE (557)
gen vote_rlp_new=.
replace vote_rlp_new=0 if inlist(country,10,14,17,25) & ess_year > 2008 & vote==1 & inlist(family_parlgov,1,2,4,6,8)
replace vote_rlp_new=1 if rlp==1 & inlist(country,10,14,17,25) & ///
	inlist(party_id,2217,1804,1441,1592,2376,2604,557) & ess_year > 2008 & vote==1 
tab1 vote_rlp_new

* vote choice for established radical left in countries with established radical left party offer
gen vote_rlp_estab=.
replace vote_rlp_estab = 0 if inlist(country,2,5,7,8,11,12,22,23,26) & ess_year > 2008 & vote==1 & inlist(family_parlgov,1,2,4,6,8)
replace vote_rlp_estab = 1 if rlp==1 & inlist(country,2,5,7,8,11,12,22,23,26) & ess_year > 2008 & vote==1 
tab1 vote_rlp_estab

* vote choice for established radical left parties in countries with rising radical left party offer
* Spain (Communist Party 118), Greece (Communist Party 614)
* and Portugal (375, 514, 281, 1295)
gen vote_rlp_estab2=. 
replace vote_rlp_estab2 = 0 if inlist(country,10,14,25) & ess_year > 2008 & vote==1 & inlist(family_parlgov,1,2,4,6,8) 
replace vote_rlp_estab2 = 1 if rlp==1 & inlist(party_id,118,614,375,514,281,1295) & inlist(country,10,14,25) & ess_year > 2008 & vote==1 
tab1 vote_rlp_estab2


* create sparse dataset for the analysis 

capture drop trstprt trstplt trstprl trstep trstun edulvlb trstplc trstlgl 
capture drop gndr freehms euftf gincdif edulvla party close ess_party_id party_vote_id 
capture drop hinctnta hinctnt hincfel stfdem stfgov stfeco stflife lrscale  
capture drop imsmetn imdfetn  imsmetn impcntr imbgeco imueclt imwbcnt minimmig maximmig
capture drop _Iclass8_2 _Iclass8_3 _Iclass8_4 _Iclass8_5 _Iclass8_6 _Iclass8_7 _Iclass8_8 
capture drop ess_close_id party_close_id party_id cabinet_id; 
capture drop educ copingi hincfeli mininsttrust maxinsttrust income immig euftf1

 
* save dataset
export delimited using ".\data\esscumulative_es.csv", nolabel replace





```



# Empirical analysis  

The following code chunk executes the analysis as implemented by HP Kriesi. You need to install the `Statamarkdown` package on your machine to execute this code directly from within R. If you prefer to execute the code from within Stata, please copy-paste the code to a do-file, store this do-file in the same directory in which you also store the folder "data" containing the `esscumulative_es.csv` and execute the code. 


```{r analysis-hpk, engine='stata', message=FALSE, include=FALSE, echo=FALSE, warning=T, eval=TRUE}

**************************************************************************************************************
* This script reproduces the results reported in 
* "Support for radical parties in Western Europe: structural conflicts and political dynamics" 
**************************************************************************************************************


import delimited "./data/esscumulative_es.csv", encoding(utf8) clear 


* install eststo command
net install st0085_2.pkg, from(http://www.stata-journal.com/software/sj14-2)
* install coefplot command
net install gr0059_1, from(http://www.stata-journal.com/software/sj15-1)

set more off
eststo clear
estimates clear
set scheme s1mono


* label variables
label var smallb "Small Business"
label var technical "Technician"
label var manager "Manager"
label var prod_worker "Production Worker"
label var clerk "Clerk"
label var service_worker "Service Worker"
label var libprof "Liberal Professional"
label var income1 "Income"
label var coping "Econ. Difficulties"
label var agea1 "Age"
label var educ1 "Level of Education"
label var immig1 "Anti-Immigration"
label var euftf1i "Pro-European"
label var gincdif1 "Pro-Redistribution"
label var freehms1 "Culturally Liberal"
label var generaldiss "Political Dissatisfaction"
label var rrp "Radical Right"
label var rlp "Radical Left"
label var male "Male"
label var essround "ESS Round"
label var cabinet "Cabinet"



/*family_parlgov	
--------------------+--------
Agrarian			|	1
Christian democracy	|	2
Communist/Socialist	|	3
Conservative		|	4
Green/Ecologist		|	5
Liberal				|	6
Right-wing			|	7
Social democracy	|	8
--------------------+--------
*/


/* party_offer: countries with only radical right, only radical left, or both parties  
--------------+--------
radical right |   1  
 radical left |   2  
     both |   3  
--------------+---------
*/



* Figure 2
* general model-social-structural characteristics
* Table A2 part1
* rrp

eststo: logit rrp coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
ib12.country [pw=dweight] if inlist(party_offer,1,3) & vote==1 & inlist(family_parlgov,1,2,4,6,7,8) , vce(cluster country) coeflegend
estimates store rad_right1

* rlp 

eststo: logit rlp coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
i.country [pw=dweight] if inlist(party_offer,2,3) & vote==1 & inlist(family_parlgov,1,2,3,4,6,8) , vce(cluster country)
estimates store rad_left1


* Table A2 part2
* rrp

eststo: logit rrp coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 euftf1i freehms1 gincdif1 generaldiss ///
i.country [pw=dweight] if inlist(party_offer,1,3) & vote==1 & inlist(family_parlgov,1,2,4,6,7,8) , vce(cluster country) coeflegend
estimates store rad_right2
quietly margins, dydx(immig1 euftf1i freehms1 gincdif1 generaldiss ) post
estimates store radical_right

* rlp 

eststo: logit rlp coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 euftf1i freehms1 gincdif1 generaldiss ///
i.country [pw=dweight] if inlist(party_offer,2,3) & vote==1 & inlist(family_parlgov,1,2,3,4,6,8) , vce(cluster country)
estimates store rad_left2
esttab rad_right1 rad_left1 rad_right2 rad_left2 using "table_A2.csv", t(3) b(3) scalars(aic bic r2_p) plain parentheses star(* 0.10 ** 0.05  *** 0.01) sfmt(2) label compress drop (*country*) replace //table A2 full table

quietly margins, dydx(immig1 euftf1i freehms1 gincdif1 generaldiss) post
estimates store radical_left

* Figure 2
coefplot ///
radical_right, bylabel(Radical Right) || radical_left, bylabel(Radical Left) || , ///
keep(immig1 euftf1i freehms1 gincdif1 generaldiss) ///
xline(0) horizontal coeflabels(, wrap(20))
graph export "fig_2.tif", width(3900)  replace


* Table A3 part1
* parties in opposition
* rrp
* dissatisfaction 
logit rrp coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
 c.immig1##c.essround euftf1i freehms1 gincdif1 c.generaldiss##c.essround ///
i.country [pw=dweight] if inlist(party_offer,1,3) & vote==1 & inlist(family_parlgov,1,2,4,6,7,8) & rrp_cabinet_all==0 , vce(cluster country)
estimates store rrp1
margins , over(essround) dydx(generaldiss) post
estimates store rrp_trend1

* immigration
logit rrp coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
 c.immig1##c.essround euftf1i freehms1 gincdif1 c.generaldiss##c.essround ///
i.country [pw=dweight] if inlist(party_offer,1,3) & vote==1 & inlist(family_parlgov,1,2,4,6,7,8) & rrp_cabinet_all==0 , vce(cluster country)
estimates store rrp1
margins , over(essround) dydx(immig1) post
estimates store rrp_trend2

* Figure A3: left-hand side
set scheme s1mono
coefplot ///
 (rrp_trend1 , label(Dissatisfaction)) ///
 (rrp_trend2 , label(Immigration)) ///
, xline(0) horizontal title("Trend Radical Right") coeflabels(, wrap(20))
graph save "figure_a3_a.gph", replace

* rlp: Table A3 part2
* dissatisfaction
logit rlp coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 euftf1i freehms1 c.gincdif1##c.essround c.generaldiss##c.essround ///
i.country [pw=dweight] if inlist(party_offer,2,3) & vote==1 & inlist(family_parlgov,1,2,3,4,6,8) & rlp_cabinet_all==0 , vce(cluster country)
estimates store rlp1

esttab rrp1 rlp1 using "table_A3.csv", t(3) b(3) scalars(aic bic r2_p) plain parentheses star(* 0.10 ** 0.05 *** 0.01) sfmt(2) label compress drop (*country*) replace // table A4 

margins , over(essround) dydx(generaldiss) post
estimates store rlp_diss

* income redistribution
logit rlp coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 euftf1i freehms1 c.gincdif1##c.essround c.generaldiss##c.essround ///
i.country [pw=dweight] if inlist(party_offer,2,3) & vote==1 & inlist(family_parlgov,1,2,3,4,6,8) & rlp_cabinet_all==0, vce(cluster country)
estimates store rlp2

margins , over(essround) dydx(gincdif1) post
estimates store rlp_income

* Figure A3: right-hand side 
coefplot ///
 (rlp_diss , label(Dissatisfaction)) ///
 (rlp_income , label(Redistribution)) , ///
xline(0) horizontal title("Trend Radical Left") coeflabels(, wrap(20))
graph save "figure_a3_b.gph", replace

* Figure A1: both sides
graph combine ///
"figure_a3_a.gph" ///
"figure_a3_b.gph" ///
, xcommon
graph export "fig_a3.tif", width(3900)  replace


* Figure 3 and Table A4
* rrp: cabinet

eststo clear
estimates clear

* in opposition
logit rrp coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 euftf1i freehms1 gincdif1 generaldiss ///
i.country [pw=dweight] if inlist(party_offer,1,3) & vote==1 & inlist(family_parlgov,1,2,4,6,7,8) & rrp_cabinet_all==0 , vce(cluster country)
estimates store rrp1
margins , dydx(immig1 generaldiss ) post
estimates store rrp_opposition

* in government
logit rrp coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 euftf1i freehms1 gincdif1 generaldiss ///
i.country [pw=dweight] if inlist(party_offer,1,3) & vote==1 & inlist(family_parlgov,1,2,4,6,7,8) & rrp_cabinet_all==1, robust
estimates store rrp2
margins , dydx(immig1 generaldiss ) post
estimates store rrp_cabinet

* Figure 3, part1
coefplot ///
 (rrp_opposition , label(In Opposition)) ///
 (rrp_cabinet , label(In Government)) , ///
xline(0) horizontal title("Radical Right") coeflabels(, wrap(20)) legend(colgap(small) keygap(tiny)) 
graph save "figure_3_a.gph", replace


* rlp: cabinet
* in opposition
logit rlp coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 euftf1i freehms1 gincdif1 generaldiss ///
i.country [pw=dweight] if inlist(party_offer,2,3) & vote==1 & inlist(family_parlgov,1,2,3,4,6,8) & rlp_cabinet_all==0 , vce(cluster country)
estimates store rlp1
margins , dydx(gincdif1 generaldiss ) post
estimates store radical_left_opposition

* in government
logit rlp coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 euftf1i freehms1 gincdif1 generaldiss ///
i.country [pw=dweight] if inlist(party_offer,2,3) & vote==1 & inlist(family_parlgov,1,2,3,4,6,8) & rlp_cabinet_all==1, robust
estimates store rlp2
esttab rrp1 rrp2 rlp1 rlp2 using "table_A4.csv", t(3) b(3) scalars(aic bic r2_p) plain parentheses star(* 0.10 ** 0.05 *** 0.01) sfmt(2) label compress drop (*country*) replac // table A5 
margins , dydx(gincdif1 generaldiss) post
estimates store radical_left_government

* Figure 3 part2 
coefplot ///
 (radical_left_opposition , label(In Opposition)) ///
 (radical_left_government , label(In Government)) , ///
xline(0) horizontal title("Radical Left") coeflabels(, wrap(20)) legend(colgap(small) keygap(tiny)) 
graph save "figure_3_b.gph", replace


* Figure 3 combined
graph combine ///
"figure_3_a.gph" ///
"figure_3_b.gph" ///
, xcommon 
graph export "fig_3.tif", width(3900)  replace


* Figure 4: interactions: general discontent, table A5

* rrp
* in opposition
eststo: logit rrp coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
euftf1i freehms1 gincdif1 ///
c.generaldiss##c.immig1##i.cabinet ///
i.country [pw=dweight] if inlist(party_offer,1,3) & vote==1 & inlist(family_parlgov,1,2,4,6,7,8) , vce(cluster country)
estimates store rrp1

quietly margins if cabinet==0 , at((mean) _all (asobserved) immig1=(0.3(.1)0.8) generaldiss=(0.3 0.8))
* Figure 4.1
marginsplot, recast(line) recastci(rarea) plot( , label("Low Disaffection" "High Disaffection")) /// 
ytitle(Probability of Choice) xtitle(Anti-Immigration) legend(col(1)) /// 
title(RR: in Opposition) 
graph save "figure_4_a.gph", replace


* in government
eststo: logit rrp coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 euftf1i freehms1 gincdif1 ///
c.generaldiss##c.immig1##i.cabinet ///
i.country [pw=dweight] if inlist(party_offer,1,3) & vote==1 & inlist(family_parlgov,1,2,4,6,7,8) , vce(cluster country)
estimates store rrp2

quietly margins if cabinet==1 , at((mean) _all (asobserved) immig1=(0.3(.1)0.8) generaldiss=(0.3 0.8))
* Figure 4.2
marginsplot, recast(line) recastci(rarea) plot( , label("Low Disaffection" "High Disaffection")) /// 
ytitle(Probability of Choice) xtitle(Anti-Immigration) legend(col(1)) /// 
title(RR: in Government) 
graph save "figure_4_b.gph", replace

* rlp
* in opposition
logit rlp coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 euftf1i freehms1 ///
c.generaldiss##i.cabinet##c.gincdif1 ///
i.country [pw=dweight] if inlist(party_offer,2,3) & vote==1 & inlist(family_parlgov,1,2,4,6,3,8) , vce(cluster country)
estimates store rlp1

quietly margins if cabinet==0 , at((mean) _all (asobserved) gincdif1=(.25(.25)1) generaldiss=(.3 .8))
* Figure 4.3
marginsplot, recast(line) recastci(rarea) plot( , label("Low Disaffection" "High Disaffection")) /// 
ytitle(Probability of Choice) xtitle(Pro-Redistribution) legend(col(1)) /// 
title(RL: in Opposition) 
graph save "figure_4_c.gph", replace


* in government
logit rlp coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 euftf1i freehms1 gincdif1 ///
c.generaldiss##i.cabinet##c.gincdif1 ///
i.country [pw=dweight] if inlist(party_offer,2,3) & vote==1 & inlist(family_parlgov,1,2,4,6,3,8) , vce(cluster country)
estimates store rlp2
esttab rrp1 rlp1 using "table_A5.csv", t(3) b(3) scalars(aic bic r2_p) plain parentheses star(* 0.10 ** 0.05 *** 0.01) sfmt(2) label compress drop (*country*) replac  // table A5

quietly margins if cabinet==1 , at((mean) _all (asobserved) gincdif1=(.25(.25)1) generaldiss=(.3 .8))
* Figure 4.4
marginsplot, recast(line) recastci(rarea) plot( , label("Low Disaffection" "High Disaffection")) /// 
ytitle(Probability of Choice) xtitle(Pro-Redistribution) legend(col(1)) /// 
title(RL: in Government) 
graph save "figure_4_d.gph", replace


graph combine ///
"figure_4_a.gph" ///
"figure_4_b.gph" ///
"figure_4_c.gph" ///
"figure_4_d.gph" ///
 , ycommon row(2) xsize(3) ysize(4) iscale(.8) 
graph export "fig_4.tif", width(3900)  replace


* Figure A4: variety of rrp: cabinet by country

* austria
logit rrp coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 freehms1 euftf1i gincdif1 generaldiss ///
 [pw=dweight] if inlist(party_offer,1,3) & vote==1 & inlist(family_parlgov,1,2,4,6,7,8) & country==1 & rrp_cabinet_all==0
estimates store rrp1
margins , dydx(immig1 generaldiss ) post
estimates store at_govt1


* austria
logit rrp coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 freehms1 euftf1i gincdif1 generaldiss ///
 [pw=dweight] if inlist(party_offer,1,3) & vote==1 & inlist(family_parlgov,1,2,4,6,7,8) & country==1 & rrp_cabinet_all==1
estimates store rrp2
margins , dydx(immig1 generaldiss ) post
estimates store at_govt2

coefplot ///
 (at_govt1 , label(In Opposition)) ///
 (at_govt2 , label(In Government)) , ///
xline(0) xscale(range(0/.5)) horizontal title("Austria") coeflabels(, wrap(20)) legend(col(1))
graph save "figure_a4_a.gph", replace 


* switzerland
logit rrp coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 freehms1 euftf1i gincdif1 generaldiss ///
 [pw=dweight] if inlist(party_offer,1,3) & vote==1 & inlist(family_parlgov,1,2,4,6,7,8) & country==4 & ess_year==2002 & /// *exclude other radical right parties from this analysis 
 !inlist(party_id,1602,628,1500)
estimates store rrp1
esttab rrp1, t(3) b(3) scalars(aic bic r2_p) plain parentheses star(* 0.10 ** 0.05 *** 0.01) sfmt(2) label compress replac //
margins , dydx(immig1 generaldiss ) post
estimates store ch_govt1

logit rrp coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 euftf1i freehms1 gincdif1 generaldiss ///
 [pw=dweight] if inlist(party_offer,1,3) & vote==1 & inlist(family_parlgov,1,2,4,6,7,8) & country==4 & inlist(ess_year,2004,2006) & /// *exclude other radical right parties from this analysis 
 !inlist(party_id,1602,628,1500)
estimates store rrp2
esttab rrp1, t(3) b(3) scalars(aic bic r2_p) plain parentheses star(* 0.10 ** 0.05 *** 0.01) sfmt(2) label compress replac //
margins , dydx(immig1 generaldiss ) post
estimates store ch_govt2

logit rrp coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 euftf1i freehms1 gincdif1 generaldiss ///
 [pw=dweight] if inlist(party_offer,1,3) & vote==1 & inlist(family_parlgov,1,2,4,6,7,8) & country==4 & inlist(ess_year,2008,2010,2012,2014,2016) & /// *exclude other radical right parties from this analysis 
 !inlist(party_id,1602,628,1500)
estimates store rrp3

margins , dydx(immig1 generaldiss ) post
estimates store ch_govt3

coefplot ///
 (ch_govt1 , label(pre-Blocher)) ///
 (ch_govt2 , label(Blocher)) ///
 (ch_govt3 , label(post-Blocher)) , ///
xline(0) horizontal title("Switzerland") coeflabels(, wrap(20)) legend(col(2))
graph save "figure_a4_b.gph", replace 


* netherlands
logit rrp coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 freehms1 euftf1i gincdif1 generaldiss ///
 [pw=dweight] if inlist(party_offer,1,3) & vote==1 & inlist(family_parlgov,1,2,4,6,7,8) & country==22 & rrp_cabinet_all==0
estimates store rrp1
margins , dydx(immig1 generaldiss ) post
estimates store nl_govt1

* 2002 no euftf1
logit rrp coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 freehms1 euftf1i gincdif1 generaldiss ///
 [pw=dweight] if inlist(party_offer,1,3) & vote==1 & inlist(family_parlgov,1,2,4,6,7,8) & country==22 & rrp_cabinet_all==1
estimates store rrp2
margins , dydx(immig1 generaldiss ) post
estimates store nl_govt2

coefplot ///
 (nl_govt1 , label(In Opposition)) ///
 (nl_govt2 , label(In Government)) , ///
xline(0) xscale(range(0/.5)) horizontal title("Netherlands") coeflabels(, wrap(20)) legend(col(1))
graph save "figure_a4_c.gph", replace 


* norway
logit rrp coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 freehms1 euftf1i gincdif1 generaldiss ///
 [pw=dweight] if inlist(party_offer,1,3) & vote==1 & inlist(family_parlgov,1,2,4,6,7,8) & country==23 & rrp_cabinet_all==0
estimates store rrp1
margins , dydx(immig1 generaldiss) post
estimates store no_govt1

logit rrp coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 euftf1i freehms1 gincdif1 generaldiss ///
 [pw=dweight] if inlist(party_offer,1,3) & vote==1 & inlist(family_parlgov,1,2,4,6,7,8) & country==23 & rrp_cabinet_all==1
estimates store rrp2
margins , dydx(immig1 generaldiss) post
estimates store no_govt2

coefplot ///
 (no_govt1 , label(In Opposition)) ///
 (no_govt2 , label(In Government)) , ///
xline(0) horizontal title("Norway") coeflabels(, wrap(20)) legend(col(1))
graph save "figure_a4_d.gph", replace 


* finland
logit rrp coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 freehms1 euftf1i gincdif1 generaldiss ///
 [pw=dweight] if inlist(party_offer,1,3) & vote==1 & inlist(family_parlgov,1,2,4,6,7,8) & country==11 & rrp_cabinet_all==0
estimates store rrp1
margins , dydx(immig1 generaldiss) post
estimates store fi_govt1

logit rrp coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 freehms1 euftf1i gincdif1 generaldiss ///
 [pw=dweight] if inlist(party_offer,1,3) & vote==1 & inlist(family_parlgov,1,2,4,6,7,8) & country==11 & rrp_cabinet_all==1
estimates store rrp2 
margins , dydx(immig1 generaldiss ) post
estimates store fi_govt2

coefplot ///
 (fi_govt1 , label(In Opposition)) ///
 (fi_govt2 , label(In Government)) , ///
xline(0) xscale(range(0/.5)) horizontal title("Finland") coeflabels(, wrap(20)) legend(col(1))
graph save "figure_a4_e.gph", replace 


* denmark
logit rrp coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 freehms1 euftf1i gincdif1 generaldiss ///
 [pw=dweight] if inlist(party_offer,1,3) & vote==1 & inlist(family_parlgov,1,2,4,6,7,8) & country==8 & rrp_cabinet_all==0
estimates store rrp1
margins , dydx(immig1 generaldiss) post
estimates store dk_govt1

logit rrp coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 freehms1 euftf1i gincdif1 generaldiss ///
 [pw=dweight] if inlist(party_offer,1,3) & vote==1 & inlist(family_parlgov,1,2,4,6,7,8) & country==8 & rrp_cabinet_all==1
estimates store rrp2
margins , dydx(immig1 generaldiss) post
estimates store dk_govt2

coefplot ///
 (nl_govt1 , label(In Opposition)) ///
 (nl_govt2 , label(In Government)) , ///
xline(0) xscale(range(0/.5)) horizontal title("Denmark") coeflabels(, wrap(20)) legend(col(1))
graph save "figure_a4_f.gph", replace 


graph combine ///
"figure_a4_a.gph" ///
"figure_a4_b.gph" ///
"figure_a4_c.gph" ///
"figure_a4_d.gph" ///
"figure_a4_e.gph" ///
"figure_a4_f.gph" ///
 , xcommon row(3) xsize(3) ysize(4) iscale(.6) 
graph export "fig_a4.tif", width(3900)  replace

 
* Figure 5: established vs new parties

* rrp: established vs new parties

* interaction with dissatisfaction
logit vote_rrp_estab coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
c.immig1##rrp_cabinet_all euftf1i freehms1 gincdif1 c.generaldiss##rrp_cabinet_all ///
i.country [pw=dweight] if inlist(party_offer,1,3) & vote==1 & inlist(family_parlgov,1,2,4,6,7,8) & rrp_new==0 & ess_year>2008 , vce(cluster country)
estimates store rrp1_new
* rrp_cabinet_all=1 & rrp_new==0 --> DK 2010, NL 2010 (late parts of fieldwork), NO 2014 & 2016
* rrp_cabinet_all=0 & rrp_new==0 --> AT 2014-2016, BE 2010-2016, DK 2012-2014, FR 2010-2016, NL 2010 (early parts of the fieldwork) 2012-2016, NO 2010-2012
margins, at(rrp_cabinet_all=(0 1)) dydx(generaldiss ) post
estimates store rrp_old_diss

logit vote_rrp_new coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
c.immig1##rrp_cabinet_all euftf1i freehms1 gincdif1 c.generaldis##rrp_cabinet_all ///
i.country [pw=dweight] if inlist(party_offer,1,3) & vote==1 & inlist(family_parlgov,1,2,4,6,7,8) & rrp_new==1 & ess_year>2008 , vce(cluster country)
estimates store rrp2_new
* rrp_cabinet_all=1 & rrp_new==1 --> FI 2016
* rrp_cabinet_all=0 & rrp_new==1 --> DE 2014-2016, FI 2010-2014, GB 2014-2016, SE 2010-2016
margins , at(rrp_cabinet_all=(0 1)) dydx(generaldiss ) post
estimates store rrp_new_diss

* Figure 5 part1
coefplot ///
 (rrp_old_diss , label(Established)) ///
 (rrp_new_diss , label(Recently rising)) ///
 , xline(0) horizontal title("Radical Right - Dissatisfaction") coeflabels(1._at = "In Opposition" 2._at = "In Government", wrap(10)) fxsize(55.5)

graph save "figure_5_a.gph", replace 
 
* interaction with immigration
logit vote_rrp_estab coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
c.immig1##rrp_cabinet_all euftf1i freehms1 gincdif1 c.generaldiss##rrp_cabinet_all ///
i.country [pw=dweight] if inlist(party_offer,1,3) & vote==1 & inlist(family_parlgov,1,2,4,6,7,8) & rrp_new==0 & ess_year>2008 , vce(cluster country)
estimates store rrp1_new
esttab rrp1_new, t(3) b(3) scalars(aic bic r2_p) plain parentheses star(* 0.10 ** 0.05 *** 0.01) sfmt(2) label compress drop (*country*) replac // table A6 (model 1) 
margins , at(rrp_cabinet_all=(0 1)) dydx(immig1) post
estimates store rrp_old_immig

logit vote_rrp_new coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
c.immig1##rrp_cabinet_all euftf1i freehms1 gincdif1 c.generaldis##rrp_cabinet_all ///
i.country [pw=dweight] if inlist(party_offer,1,3) & vote==1 & inlist(family_parlgov,1,2,4,6,7,8) & rrp_new==1 & ess_year>2008 , vce(cluster country)
estimates store rrp2_new

margins , at(rrp_cabinet_all=(0 1)) dydx(immig1) post
estimates store rrp_new_immig

* Figure 5 part2
coefplot ///
 (rrp_old_immig , label(Established)) ///
 (rrp_new_immig , label(Recently rising)) ///
 , xline(0) horizontal title("Radical Right - Immigration") coeflabels(1._at = " " 2._at = " ") fxsize(44.5)
graph save "figure_5_b.gph", replace 


* rlp: Established vs new parties 
* interaction with dissatisfaction
* countries with Established radical left parties
logit vote_rlp_estab coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 euftf1i freehms1 c.gincdif1##rlp_cabinet_all c.generaldiss##rlp_cabinet_all ///
i.country [pw=dweight] if inlist(party_offer,2,3) & vote==1 & inlist(family_parlgov,1,2,4,6,3,8) & rlp_new==0 & ess_year>2008 , vce(cluster country)
estimates store rlp1_new
margins , at(rlp_cabinet_all=(0 1)) dydx(generaldiss) post
estimates store rlp_old_diss

* countries with new radical left parties, outcome: vote for new radical left party
logit vote_rlp_new coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 euftf1i freehms1 c.gincdif1##rlp_cabinet_all c.generaldiss##rlp_cabinet_all ///
i.country [pw=dweight] if inlist(party_offer,2,3) & vote==1 & inlist(family_parlgov,1,2,4,6,3,8) & rlp_new==1 & ess_year>2008 , vce(cluster country)
estimates store rlp2_new
esttab rrp1_new rrp2_new rlp1_new rlp2_new using "table_A6.csv", t(3) b(3) scalars(aic bic r2_p) plain parentheses star(* 0.10 ** 0.05 *** 0.01) sfmt(2) label compress drop (*country*) replac // table A6
 
margins , at(rlp_cabinet_all=(0 1)) dydx(generaldiss) post
estimates store rlp_new_diss

* Figure 5 part3
coefplot ///
 (rlp_old_diss , label(Established)) ///
 (rlp_new_diss , label(Recently rising)) ///
 , xline(0) horizontal title("Radical Left - Dissatisfaction") coeflabels(1._at = "In Opposition" 2._at = "In Government", wrap(10)) fxsize(55.5)
graph save "figure_5_c.gph", replace 


* interaction with gincdif1
logit vote_rlp_estab coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 euftf1i freehms1 c.gincdif1##rlp_cabinet_all c.generaldiss##rlp_cabinet_all ///
i.country [pw=dweight] if inlist(party_offer,2,3) & vote==1 & inlist(family_parlgov,1,2,4,6,3,8) & rlp_new==0 & ess_year>2008 , vce(cluster country)
estimates store rlp1
margins , at(rlp_cabinet_all=(0 1)) dydx(gincdif1) post
estimates store rlp_old_redist

logit vote_rlp_new coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 euftf1i freehms1 c.gincdif1##rlp_cabinet_all c.generaldiss##rlp_cabinet_all ///
i.country [pw=dweight] if inlist(party_offer,2,3) & vote==1 & inlist(family_parlgov,1,2,4,6,3,8) & rlp_new==1 & ess_year>2008 , vce(cluster country)
estimates store rlp2

margins , at(rlp_cabinet_all=(0 1)) dydx(gincdif1 ) post
estimates store rlp_new_redist

* Figure 5 part4
coefplot ///
 (rlp_old_redist , label(Established)) ///
 (rlp_new_redist , label(Recently rising)) ///
 , xline(0) horizontal title("Radical Left - Income Distribution") coeflabels(1._at = " " 2._at = " ") fxsize(44.5)
 graph save "figure_5_d.gph", replace 

 
graph combine ///
"figure_5_a.gph" ///
"figure_5_b.gph" ///
"figure_5_c.gph" ///
"figure_5_d.gph" ///
 , ycommon xcommon row(2) xsize(3) ysize(4) iscale(.6) 
graph export "fig_5.tif", width(3900)  replace


 
* Figure A5
* rlp - established vs new in countries with rising radical left party offer plus Cyprus

* Spain
logit vote_rlp_estab2 coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 euftf1i freehms1 gincdif1 generaldiss ///
 [pw=dweight] if inlist(party_offer,2,3) & vote==1 & inlist(family_parlgov,1,2,4,6,3,8) & country==10 & ess_year>2008 
estimates store rlp1 
margins , dydx(gincdif1 freehms1 generaldiss ) post
estimates store es_estab

logit vote_rlp_new coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 euftf1i freehms1 gincdif1 generaldiss ///
 [pw=dweight] if inlist(party_offer,2,3) & vote==1 & inlist(family_parlgov,1,2,4,6,3,8) & country==10 & ess_year>2008 
estimates store rlp2
esttab rlp1 rlp2 , t(3) b(3) scalars(aic bic r2_p) plain parentheses star(* 0.10 ** 0.05 *** 0.01) sfmt(2) label compress replac // table A6 (model 1) 
margins , dydx(gincdif1 freehms1 generaldiss ) post
estimates store es_new

* Figure Spain
coefplot ///
 (es_estab , label(Established)) ///
 (es_new , label(Recently rising)) , ///
xline(0) xscale(range(0/.5)) horizontal title("Spain") coeflabels(, wrap(20)) legend(col(1))
graph save "figure_a5_a.gph", replace 


* Portugal
logit vote_rlp_estab2 coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 euftf1i freehms1 gincdif1 generaldiss ///
 [pw=dweight] if inlist(party_offer,2,3) & vote==1 & inlist(family_parlgov,1,2,4,6,3,8) & country==25 & ess_year>2008 
estimates store rlp1
margins , dydx(gincdif1 freehms1 generaldiss) post
estimates store pt_estab

logit vote_rlp_new coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 euftf1i freehms1 gincdif1 generaldiss ///
 [pw=dweight] if inlist(party_offer,2,3) & vote==1 & inlist(family_parlgov,1,2,4,6,3,8) & country==25 & ess_year>2008 
estimates store rlp2
margins , dydx(gincdif1 freehms1 generaldiss) post
estimates store pt_new

* Figure Portugal
coefplot ///
 (pt_estab , label(Established)) ///
 (pt_new , label(Recently rising)) , ///
xline(0) xscale(range(0/.5)) horizontal title("Portugal") coeflabels(, wrap(20)) legend(col(1))
graph save "figure_a5_b.gph", replace 


* Greece
logit vote_rlp_estab2 coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 euftf1i freehms1 gincdif1 generaldiss ///
 [pw=dweight] if inlist(party_offer,2,3) & vote==1 & inlist(family_parlgov,1,2,4,6,3,8) & country==14 & ess_year>2008 
estimates store rlp1
margins , dydx(gincdif1 freehms1 generaldiss ) post
estimates store gr_estab

logit vote_rlp_new coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 euftf1i freehms1 gincdif1 generaldiss ///
 [pw=dweight] if inlist(party_offer,2,3) & vote==1 & inlist(family_parlgov,1,2,4,6,3,8) & country==14 & ess_year>2008 
estimates store rlp2
margins , dydx(gincdif1 freehms1 generaldiss ) post
estimates store gr_new

* Figure Greece
coefplot ///
 (gr_estab , label(Established)) ///
 (gr_new , label(Recently rising)) , ///
xline(0) xscale(range(0/.5)) horizontal title("Greece") coeflabels(, wrap(20)) legend(col(1))
graph save "figure_a5_c.gph", replace 


* Cyprus vs Ireland
logit vote_rlp_estab coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 euftf1i freehms1 gincdif1 generaldiss ///
 [pw=dweight] if inlist(party_offer,2,3) & vote==1 & inlist(family_parlgov,1,2,4,6,3,8) & country==5 & ess_year>2008 
estimates store rlp1
margins , dydx(gincdif1 freehms1 generaldiss ) post
estimates store cy_estab

logit vote_rlp_new coping educ1 income1 libprof smallb technical manager clerk service_worker prod_worker agea1 male ///
immig1 euftf1i freehms1 gincdif1 generaldiss ///
 [pw=dweight] if inlist(party_offer,2,3) & vote==1 & inlist(family_parlgov,1,2,4,6,3,8) & country==17 & ess_year>2008 
estimates store rlp2
margins , dydx(gincdif1 freehms1 generaldiss ) post
estimates store ir_new

* Figure Cyprus-Ireland
coefplot ///
 (cy_estab , label(Cyprus - Established)) ///
 (ir_new , label(Ireland - Recently rising)) , ///
xline(0) xscale(range(0/.5)) horizontal title("Cyprus-Ireland") coeflabels(, wrap(20)) legend(col(1))
graph save "figure_a5_d.gph", replace 

graph combine ///
"figure_a5_a.gph" ///
"figure_a5_b.gph" ///
"figure_a5_c.gph" ///
"figure_a5_d.gph" ///
 , ycommon row(2) xsize(3) ysize(4) iscale(.6) 
graph export "fig_a5.tif", width(3900)  replace


```




